import { getBaseURL, get, post, deletes } from "./request";
const HttpManager = {
    // 获取图片信息   后台数据包含/所以此处直接使用${url}而不是/${url}
    attachImageUrl: (url) => url ? `${getBaseURL()}${url}` : "https://cube.elemecdn.com/e/fd/0fc7d20532fdaf769a25683617711png.png",

    //获取所有的海报
    getBannerList: () => get("banner/getAllBanner"),

 // =======================> 评分 API 完成
    // 提交评分
    setRank: ({ songListId, consumerId, score }) => post(`rankList/add`, { songListId, consumerId, score }),
     // 获取指定歌单的评分
     getRankOfSongListId: (songListId) => get(`rankList?songListId=${songListId}`),  
     getUserRank:(consumerId, songListId)=>get(`rankList/user?songListId=${songListId}&consumerId=${consumerId}`),
    // =======================> 歌单 API 完成
    // 获取全部歌单
    getSongList: () => get("song"),
    // 返回标题包含文字的歌单
    getSongListOfLikeTitle: (keywords) => get(`songlist/likeTitle/detail?title=${keywords}`),
    // 返回标题包含文字的歌单
    getSongListOfStyle: (style) => get(`songlist/style/detail?style=${style}`),
    getSongsOfSongListId:(songListId)=> get(`/song/listBySongListId?songListId=${songListId}`),
    // =======================> 歌手 API  完成
    // 返回所有歌手
    getAllSinger: () => get("singer/list"),
    getSingerOfSex:(sex)=>get(`singer/listbySex?sex=${sex}`),
    
    // =======================> 歌曲 API
    // 返回指定歌手名的歌曲
    getSongOfSingerName: (keywords) => get(`song/singerName/detail?name=${keywords}`),
    getSongOfSingerId:(userId)=>get(`/song/listByUserId?userId=${userId}`),
    signIn:({ username, password }) => post("user/login/status", { username, password }),
    SignUp:(user) => post("user/add", user),
    getUserOfId:(id) => get(`userbyId?id=${id}`),
    getCollectionOfUser:(id) => get(`collection/detail?id=${id}`),
    getSongOfId:(id) => get(`song/detail?id=${id}`),
     // 更新用户信息
     updateUserMsg: ({ id, username, sex, phoneNum, email, birth, introduction, location }) => post(`user/update`, { id, username, sex, phoneNum, email, birth, introduction, location }),
     // 删除用户
     deleteUser: (id) => get(`user/delete?id=${id}`),
     // 更新用户头像
     uploadUrl: (userId) => `${getBaseURL()}/user/avatar/update?id=${userId}`,
     // 更新用户密码
     updateUserPassword: ({ id, username, oldPassword, password }) => post(`user/updatePassword`, { id, username, oldPassword, password }),

     // 添加评论
     setComment: ({ userId, content, songId, songListId, nowType }) => post(`comment/add`, { userId, content, songId, songListId, nowType }),
     // 添加评论
     deleteComment: (id) => get(`comment/delete?id=${id}`),
     // 返回所有评论
     getAllComment: (type, id) => {let url = "";if (type === 1) { url = `comment/songList/${id}`;} else if (type === 0) {url = `comment/song/detail?songId=${id}`;}return get(url);},

    //======================> 点赞api的优化 避免有些是重复的点赞
    testAlreadySupport: ({ commentId, userId }) => post(`userSupport/test`, { commentId, userId }),

    deleteUserSupport: ({ commentId, userId }) => post(`userSupport/delete`, { commentId, userId }),

    insertUserSupport: ({ commentId, userId }) => post(`userSupport/insert`, { commentId, userId }),

    // 点赞
    setSupport: ({ id, up }) => post(`comment/like`, { id, up }),

     //=======================>购物车
     addCart:(songId, userId, price) => post(`cart/add`,{songId, userId, price}),
     //获取当前用户购物车所有歌曲信息
     getCartList: (userId) => get(`cart/list?userId=${userId}`),
     //删除当前用户购物车中指定歌曲
     deleteCartList: (userId, delSongIds) => get(`cart/remove?userId=${userId}&cartListIds=${delSongIds}`),
      // 歌曲是否支付
    getPaystatus: (songId, userId) => get(`song/isPay?songId=${songId}&userId=${userId}`),
    // 支付歌曲费用
    toPay: (songIds, userId, payType) => post(`pay/common/alipay?songIds=${songIds}&userId=${userId}&payType=${payType}`),
    }
export { HttpManager };